<?php

namespace App\Console;

use App\Http\Controllers\Api\CrontabController;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            file_put_contents('/var/log/crontab_run.log', date('Y-m-d H:i:s')."\r\n", FILE_APPEND);
            $crontab = new CrontabController();
            $data = $crontab->query_all_order();
            file_put_contents('/var/log/crontab_run.log', '订单同步方法：'.$data."\r\n", FILE_APPEND);
        })->everyMinute(); // 每分钟运行一次

        $schedule->call(function () {
            file_put_contents('/var/log/crontab_run.log', date('Y-m-d H:i:s')."\r\n", FILE_APPEND);
            $crontab = new CrontabController();
            $plan_data = $crontab->phoneMealDataMove();
            file_put_contents('/var/log/crontab_run.log', '同步套餐方法：'.$plan_data."\r\n", FILE_APPEND);
        })->daily(); // 每天凌晨运行
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
